package com.iflytek.sbd.demo.threadlocal;

import org.springframework.core.NamedThreadLocal;
import org.springframework.core.io.support.EncodedResource;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;

/**
 * @program: sbd
 * @description: 发现源码里面XmlBeanDefinitionReader的resourcesCurrentlyBeingLoaded属性是一个ThreadLocal看不懂, 研究一下
 * @author: 陈英俊
 * @create: 2021-12-28 09:19
 */
public class ThreadLocalDemo {
    /**
     * new 一个子类NamedThreadLocal ,使用父类ThreadLocal 来引用, 可以在子类屁股{},重写父类或者子类的方法
     * 实际是匿名子类实现子类继承父类的方法
     */

    private final ThreadLocal<Set<EncodedResource>> resourcesCurrentlyBeingLoaded =
            new NamedThreadLocal<Set<EncodedResource>>("XML bean definition resources currently being loaded") {
                @Override
                protected Set<EncodedResource> initialValue() {
                    return new HashSet<>(4);
                }
            };


    public static void main(String[] args) {

    }
}
